
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>模块 · TypeScript Handbook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Patrick Zhong">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Namespaces.html" />
    
    
    <link rel="prev" href="Iterators and Generators.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="tutorials/">
            
                <a href="tutorials/">
            
                    
                    快速上手
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="tutorials/TypeScript in 5 minutes.html">
            
                <a href="tutorials/TypeScript in 5 minutes.html">
            
                    
                    5分钟了解TypeScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="tutorials/ASP.NET Core.html">
            
                <a href="tutorials/ASP.NET Core.html">
            
                    
                    ASP.NET Core
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="tutorials/ASP.NET 4.html">
            
                <a href="tutorials/ASP.NET 4.html">
            
                    
                    ASP.NET 4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="tutorials/Gulp.html">
            
                <a href="tutorials/Gulp.html">
            
                    
                    Gulp
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="tutorials/Knockout.html">
            
                <a href="tutorials/Knockout.html">
            
                    
                    Knockout.js
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="tutorials/React & Webpack.html">
            
                <a href="tutorials/React & Webpack.html">
            
                    
                    React与webpack
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="tutorials/React.html">
            
                <a href="tutorials/React.html">
            
                    
                    React
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="tutorials/Angular 2.html">
            
                <a href="tutorials/Angular 2.html">
            
                    
                    Angular 2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="tutorials/Migrating from JavaScript.html">
            
                <a href="tutorials/Migrating from JavaScript.html">
            
                    
                    从JavaScript迁移到TypeScript
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="./">
            
                <a href="./">
            
                    
                    手册
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="Basic Types.html">
            
                <a href="Basic Types.html">
            
                    
                    基础类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="Variable Declarations.html">
            
                <a href="Variable Declarations.html">
            
                    
                    变量声明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="Interfaces.html">
            
                <a href="Interfaces.html">
            
                    
                    接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="Classes.html">
            
                <a href="Classes.html">
            
                    
                    类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="Functions.html">
            
                <a href="Functions.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="Generics.html">
            
                <a href="Generics.html">
            
                    
                    泛型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="Enums.html">
            
                <a href="Enums.html">
            
                    
                    枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="Type Inference.html">
            
                <a href="Type Inference.html">
            
                    
                    类型推论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="Type Compatibility.html">
            
                <a href="Type Compatibility.html">
            
                    
                    类型兼容性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="Advanced Types.html">
            
                <a href="Advanced Types.html">
            
                    
                    高级类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="Utilit Types.md">
            
                <span>
            
                    
                    实用工具类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="Symbols.html">
            
                <a href="Symbols.html">
            
                    
                    Symbols
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="Iterators and Generators.html">
            
                <a href="Iterators and Generators.html">
            
                    
                    Iterators 和 Generators
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.14" data-path="Modules.html">
            
                <a href="Modules.html">
            
                    
                    模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.15" data-path="Namespaces.html">
            
                <a href="Namespaces.html">
            
                    
                    命名空间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.16" data-path="Namespaces and Modules.html">
            
                <a href="Namespaces and Modules.html">
            
                    
                    命名空间和模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.17" data-path="Module Resolution.html">
            
                <a href="Module Resolution.html">
            
                    
                    模块解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.18" data-path="Declaration Merging.html">
            
                <a href="Declaration Merging.html">
            
                    
                    声明合并
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.19" data-path="Writing Definition Files.html">
            
                <a href="Writing Definition Files.html">
            
                    
                    书写.d.ts文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.20" data-path="JSX.html">
            
                <a href="JSX.html">
            
                    
                    JSX
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.21" data-path="Decorators.html">
            
                <a href="Decorators.html">
            
                    
                    Decorators
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.22" data-path="Mixins.html">
            
                <a href="Mixins.html">
            
                    
                    混入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.23" data-path="Triple-Slash Directives.html">
            
                <a href="Triple-Slash Directives.html">
            
                    
                    三斜线指令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.24" data-path="Type Checking JavaScript Files.html">
            
                <a href="Type Checking JavaScript Files.html">
            
                    
                    JavaScript文件里的类型检查
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="declaration files/Introduction.html">
            
                <a href="declaration files/Introduction.html">
            
                    
                    如何书写声明文件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="declaration files/Library Structures.html">
            
                <a href="declaration files/Library Structures.html">
            
                    
                    结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="declaration files/Do's and Don'ts.html">
            
                <a href="declaration files/Do's and Don'ts.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="declaration files/By Example.html">
            
                <a href="declaration files/By Example.html">
            
                    
                    举例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="declaration files/Deep Dive.html">
            
                <a href="declaration files/Deep Dive.html">
            
                    
                    深入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="declaration files/Publishing.html">
            
                <a href="declaration files/Publishing.html">
            
                    
                    发布
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="declaration files/Consumption.html">
            
                <a href="declaration files/Consumption.html">
            
                    
                    使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="tsconfig.json.html">
            
                <a href="tsconfig.json.html">
            
                    
                    工程配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="tsconfig.json.html">
            
                <a href="tsconfig.json.html">
            
                    
                    tsconfig.json
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="Project References.html">
            
                <a href="Project References.html">
            
                    
                    工程引用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="Typings for NPM Packages.html">
            
                <a href="Typings for NPM Packages.html">
            
                    
                    NPM包的类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="Compiler Options.html">
            
                <a href="Compiler Options.html">
            
                    
                    编译选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="Configuring Watch.html">
            
                <a href="Configuring Watch.html">
            
                    
                    配置 Watch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="Compiler Options in MSBuild.html">
            
                <a href="Compiler Options in MSBuild.html">
            
                    
                    在MSBuild里使用编译选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="Integrating with Build Tools.html">
            
                <a href="Integrating with Build Tools.html">
            
                    
                    与其它构建工具整合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="Nightly Builds.html">
            
                <a href="Nightly Builds.html">
            
                    
                    使用TypeScript的每日构建版本
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../wiki/">
            
                <a href="../wiki/">
            
                    
                    Wiki
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../wiki/this-in-TypeScript.html">
            
                <a href="../wiki/this-in-TypeScript.html">
            
                    
                    TypeScript里的this
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../wiki/coding_guidelines.html">
            
                <a href="../wiki/coding_guidelines.html">
            
                    
                    编码规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../wiki/Common Errors.html">
            
                <a href="../wiki/Common Errors.html">
            
                    
                    常见编译错误
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../wiki/TypeScript-Editor-Support.html">
            
                <a href="../wiki/TypeScript-Editor-Support.html">
            
                    
                    支持TypeScript的编辑器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../wiki/Using-TypeScript-With-ASP.NET-5.html">
            
                <a href="../wiki/Using-TypeScript-With-ASP.NET-5.html">
            
                    
                    结合ASP.NET v5使用TypeScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../wiki/Architectural-Overview.html">
            
                <a href="../wiki/Architectural-Overview.html">
            
                    
                    架构概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../wiki/Roadmap.html">
            
                <a href="../wiki/Roadmap.html">
            
                    
                    发展路线图
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../release-notes/">
            
                <a href="../release-notes/">
            
                    
                    新增功能
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../release-notes/TypeScript 3.1.html">
            
                <a href="../release-notes/TypeScript 3.1.html">
            
                    
                    TypeScript 3.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../release-notes/TypeScript 3.0.html">
            
                <a href="../release-notes/TypeScript 3.0.html">
            
                    
                    TypeScript 3.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../release-notes/TypeScript 2.9.html">
            
                <a href="../release-notes/TypeScript 2.9.html">
            
                    
                    TypeScript 2.9
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../release-notes/TypeScript 2.8.html">
            
                <a href="../release-notes/TypeScript 2.8.html">
            
                    
                    TypeScript 2.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../release-notes/TypeScript 2.7.html">
            
                <a href="../release-notes/TypeScript 2.7.html">
            
                    
                    TypeScript 2.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../release-notes/TypeScript 2.6.html">
            
                <a href="../release-notes/TypeScript 2.6.html">
            
                    
                    TypeScript 2.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../release-notes/TypeScript 2.5.html">
            
                <a href="../release-notes/TypeScript 2.5.html">
            
                    
                    TypeScript 2.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../release-notes/TypeScript 2.4.html">
            
                <a href="../release-notes/TypeScript 2.4.html">
            
                    
                    TypeScript 2.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="../release-notes/TypeScript 2.3.html">
            
                <a href="../release-notes/TypeScript 2.3.html">
            
                    
                    TypeScript 2.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.10" data-path="../release-notes/TypeScript 2.2.html">
            
                <a href="../release-notes/TypeScript 2.2.html">
            
                    
                    TypeScript 2.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.11" data-path="../release-notes/TypeScript 2.1.html">
            
                <a href="../release-notes/TypeScript 2.1.html">
            
                    
                    TypeScript 2.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.12" data-path="../release-notes/TypeScript 2.0.html">
            
                <a href="../release-notes/TypeScript 2.0.html">
            
                    
                    TypeScript 2.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.13" data-path="../release-notes/TypeScript 1.8.html">
            
                <a href="../release-notes/TypeScript 1.8.html">
            
                    
                    TypeScript 1.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.14" data-path="../release-notes/TypeScript 1.7.html">
            
                <a href="../release-notes/TypeScript 1.7.html">
            
                    
                    TypeScript 1.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.15" data-path="../release-notes/TypeScript 1.6.html">
            
                <a href="../release-notes/TypeScript 1.6.html">
            
                    
                    TypeScript 1.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.16" data-path="../release-notes/TypeScript 1.5.html">
            
                <a href="../release-notes/TypeScript 1.5.html">
            
                    
                    TypeScript 1.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.17" data-path="../release-notes/TypeScript 1.4.html">
            
                <a href="../release-notes/TypeScript 1.4.html">
            
                    
                    TypeScript 1.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.18" data-path="../release-notes/TypeScript 1.3.html">
            
                <a href="../release-notes/TypeScript 1.3.html">
            
                    
                    TypeScript 1.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.19" data-path="../release-notes/TypeScript 1.1.html">
            
                <a href="../release-notes/TypeScript 1.1.html">
            
                    
                    TypeScript 1.1
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../breaking-changes/breaking-changes.html">
            
                <a href="../breaking-changes/breaking-changes.html">
            
                    
                    Breaking Changes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../breaking-changes/TypeScript 2.4.html">
            
                <a href="../breaking-changes/TypeScript 2.4.html">
            
                    
                    TypeScript 2.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../breaking-changes/TypeScript 2.3.html">
            
                <a href="../breaking-changes/TypeScript 2.3.html">
            
                    
                    TypeScript 2.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../breaking-changes/TypeScript 2.2.html">
            
                <a href="../breaking-changes/TypeScript 2.2.html">
            
                    
                    TypeScript 2.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../breaking-changes/TypeScript 2.1.html">
            
                <a href="../breaking-changes/TypeScript 2.1.html">
            
                    
                    TypeScript 2.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../breaking-changes/TypeScript 2.0.html">
            
                <a href="../breaking-changes/TypeScript 2.0.html">
            
                    
                    TypeScript 2.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../breaking-changes/TypeScript 1.8.html">
            
                <a href="../breaking-changes/TypeScript 1.8.html">
            
                    
                    TypeScript 1.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../breaking-changes/TypeScript 1.7.html">
            
                <a href="../breaking-changes/TypeScript 1.7.html">
            
                    
                    TypeScript 1.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="../breaking-changes/TypeScript 1.6.html">
            
                <a href="../breaking-changes/TypeScript 1.6.html">
            
                    
                    TypeScript 1.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="../breaking-changes/TypeScript 1.5.html">
            
                <a href="../breaking-changes/TypeScript 1.5.html">
            
                    
                    TypeScript 1.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.10" data-path="../breaking-changes/TypeScript 1.4.html">
            
                <a href="../breaking-changes/TypeScript 1.4.html">
            
                    
                    TypeScript 1.4
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >模块</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <blockquote>
<p><strong>&#x5173;&#x4E8E;&#x672F;&#x8BED;&#x7684;&#x4E00;&#x70B9;&#x8BF4;&#x660E;:</strong>
&#x8BF7;&#x52A1;&#x5FC5;&#x6CE8;&#x610F;&#x4E00;&#x70B9;&#xFF0C;TypeScript 1.5&#x91CC;&#x672F;&#x8BED;&#x540D;&#x5DF2;&#x7ECF;&#x53D1;&#x751F;&#x4E86;&#x53D8;&#x5316;&#x3002;
&#x201C;&#x5185;&#x90E8;&#x6A21;&#x5757;&#x201D;&#x73B0;&#x5728;&#x79F0;&#x505A;&#x201C;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x201D;&#x3002;
&#x201C;&#x5916;&#x90E8;&#x6A21;&#x5757;&#x201D;&#x73B0;&#x5728;&#x5219;&#x7B80;&#x79F0;&#x4E3A;&#x201C;&#x6A21;&#x5757;&#x201D;&#xFF0C;&#x8FD9;&#x662F;&#x4E3A;&#x4E86;&#x4E0E;<a href="http://www.ecma-international.org/ecma-262/6.0/" target="_blank">ECMAScript 2015</a>&#x91CC;&#x7684;&#x672F;&#x8BED;&#x4FDD;&#x6301;&#x4E00;&#x81F4;&#xFF0C;(&#x4E5F;&#x5C31;&#x662F;&#x8BF4; <code>module X {</code> &#x76F8;&#x5F53;&#x4E8E;&#x73B0;&#x5728;&#x63A8;&#x8350;&#x7684;&#x5199;&#x6CD5; <code>namespace X {</code>)&#x3002;</p>
</blockquote>
<h1 id="&#x4ECB;&#x7ECD;">&#x4ECB;&#x7ECD;</h1>
<p>&#x4ECE;ECMAScript 2015&#x5F00;&#x59CB;&#xFF0C;JavaScript&#x5F15;&#x5165;&#x4E86;&#x6A21;&#x5757;&#x7684;&#x6982;&#x5FF5;&#x3002;TypeScript&#x4E5F;&#x6CBF;&#x7528;&#x8FD9;&#x4E2A;&#x6982;&#x5FF5;&#x3002;</p>
<p>&#x6A21;&#x5757;&#x5728;&#x5176;&#x81EA;&#x8EAB;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x91CC;&#x6267;&#x884C;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x5728;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x91CC;&#xFF1B;&#x8FD9;&#x610F;&#x5473;&#x7740;&#x5B9A;&#x4E49;&#x5728;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x91CC;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x51FD;&#x6570;&#xFF0C;&#x7C7B;&#x7B49;&#x7B49;&#x5728;&#x6A21;&#x5757;&#x5916;&#x90E8;&#x662F;&#x4E0D;&#x53EF;&#x89C1;&#x7684;&#xFF0C;&#x9664;&#x975E;&#x4F60;&#x660E;&#x786E;&#x5730;&#x4F7F;&#x7528;<a href="#export"><code>export</code>&#x5F62;&#x5F0F;</a>&#x4E4B;&#x4E00;&#x5BFC;&#x51FA;&#x5B83;&#x4EEC;&#x3002;
&#x76F8;&#x53CD;&#xFF0C;&#x5982;&#x679C;&#x60F3;&#x4F7F;&#x7528;&#x5176;&#x5B83;&#x6A21;&#x5757;&#x5BFC;&#x51FA;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x51FD;&#x6570;&#xFF0C;&#x7C7B;&#xFF0C;&#x63A5;&#x53E3;&#x7B49;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F60;&#x5FC5;&#x987B;&#x8981;&#x5BFC;&#x5165;&#x5B83;&#x4EEC;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<a href="#import"><code>import</code>&#x5F62;&#x5F0F;</a>&#x4E4B;&#x4E00;&#x3002;</p>
<p>&#x6A21;&#x5757;&#x662F;&#x81EA;&#x58F0;&#x660E;&#x7684;&#xFF1B;&#x4E24;&#x4E2A;&#x6A21;&#x5757;&#x4E4B;&#x95F4;&#x7684;&#x5173;&#x7CFB;&#x662F;&#x901A;&#x8FC7;&#x5728;&#x6587;&#x4EF6;&#x7EA7;&#x522B;&#x4E0A;&#x4F7F;&#x7528;imports&#x548C;exports&#x5EFA;&#x7ACB;&#x7684;&#x3002;</p>
<p>&#x6A21;&#x5757;&#x4F7F;&#x7528;&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#x53BB;&#x5BFC;&#x5165;&#x5176;&#x5B83;&#x7684;&#x6A21;&#x5757;&#x3002;
&#x5728;&#x8FD0;&#x884C;&#x65F6;&#xFF0C;&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#x7684;&#x4F5C;&#x7528;&#x662F;&#x5728;&#x6267;&#x884C;&#x6B64;&#x6A21;&#x5757;&#x4EE3;&#x7801;&#x524D;&#x53BB;&#x67E5;&#x627E;&#x5E76;&#x6267;&#x884C;&#x8FD9;&#x4E2A;&#x6A21;&#x5757;&#x7684;&#x6240;&#x6709;&#x4F9D;&#x8D56;&#x3002;
&#x5927;&#x5BB6;&#x6700;&#x719F;&#x77E5;&#x7684;JavaScript&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#x662F;&#x670D;&#x52A1;&#x4E8E;Node.js&#x7684;<a href="https://en.wikipedia.org/wiki/CommonJS" target="_blank">CommonJS</a>&#x548C;&#x670D;&#x52A1;&#x4E8E;Web&#x5E94;&#x7528;&#x7684;<a href="http://requirejs.org/" target="_blank">Require.js</a>&#x3002;</p>
<p>TypeScript&#x4E0E;ECMAScript 2015&#x4E00;&#x6837;&#xFF0C;&#x4EFB;&#x4F55;&#x5305;&#x542B;&#x9876;&#x7EA7;<code>import</code>&#x6216;&#x8005;<code>export</code>&#x7684;&#x6587;&#x4EF6;&#x90FD;&#x88AB;&#x5F53;&#x6210;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x3002;
&#x76F8;&#x53CD;&#x5730;&#xFF0C;&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x4E0D;&#x5E26;&#x6709;&#x9876;&#x7EA7;&#x7684;<code>import</code>&#x6216;&#x8005;<code>export</code>&#x58F0;&#x660E;&#xFF0C;&#x90A3;&#x4E48;&#x5B83;&#x7684;&#x5185;&#x5BB9;&#x88AB;&#x89C6;&#x4E3A;&#x5168;&#x5C40;&#x53EF;&#x89C1;&#x7684;&#xFF08;&#x56E0;&#x6B64;&#x5BF9;&#x6A21;&#x5757;&#x4E5F;&#x662F;&#x53EF;&#x89C1;&#x7684;&#xFF09;&#x3002;</p>
<h1 id="&#x5BFC;&#x51FA;"><a name="export"></a>&#x5BFC;&#x51FA;</h1>
<h2 id="&#x5BFC;&#x51FA;&#x58F0;&#x660E;">&#x5BFC;&#x51FA;&#x58F0;&#x660E;</h2>
<p>&#x4EFB;&#x4F55;&#x58F0;&#x660E;&#xFF08;&#x6BD4;&#x5982;&#x53D8;&#x91CF;&#xFF0C;&#x51FD;&#x6570;&#xFF0C;&#x7C7B;&#xFF0C;&#x7C7B;&#x578B;&#x522B;&#x540D;&#x6216;&#x63A5;&#x53E3;&#xFF09;&#x90FD;&#x80FD;&#x591F;&#x901A;&#x8FC7;&#x6DFB;&#x52A0;<code>export</code>&#x5173;&#x952E;&#x5B57;&#x6765;&#x5BFC;&#x51FA;&#x3002;</p>
<h5 id="validationts">Validation.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> <span class="hljs-keyword">interface</span> StringValidator {
    isAcceptable(s: <span class="hljs-built_in">string</span>): <span class="hljs-built_in">boolean</span>;
}
</code></pre>
<h5 id="zipcodevalidatorts">ZipCodeValidator.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> numberRegexp = <span class="hljs-regexp">/^[0-9]+$/</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> ZipCodeValidator <span class="hljs-keyword">implements</span> StringValidator {
    isAcceptable(s: <span class="hljs-built_in">string</span>) {
        <span class="hljs-keyword">return</span> s.length === <span class="hljs-number">5</span> &amp;&amp; numberRegexp.test(s);
    }
}
</code></pre>
<h2 id="&#x5BFC;&#x51FA;&#x8BED;&#x53E5;">&#x5BFC;&#x51FA;&#x8BED;&#x53E5;</h2>
<p>&#x5BFC;&#x51FA;&#x8BED;&#x53E5;&#x5F88;&#x4FBF;&#x5229;&#xFF0C;&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#x53EF;&#x80FD;&#x9700;&#x8981;&#x5BF9;&#x5BFC;&#x51FA;&#x7684;&#x90E8;&#x5206;&#x91CD;&#x547D;&#x540D;&#xFF0C;&#x6240;&#x4EE5;&#x4E0A;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x53EF;&#x4EE5;&#x8FD9;&#x6837;&#x6539;&#x5199;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">class</span> ZipCodeValidator <span class="hljs-keyword">implements</span> StringValidator {
    isAcceptable(s: <span class="hljs-built_in">string</span>) {
        <span class="hljs-keyword">return</span> s.length === <span class="hljs-number">5</span> &amp;&amp; numberRegexp.test(s);
    }
}
<span class="hljs-keyword">export</span> { ZipCodeValidator };
<span class="hljs-keyword">export</span> { ZipCodeValidator as mainValidator };
</code></pre>
<h2 id="&#x91CD;&#x65B0;&#x5BFC;&#x51FA;">&#x91CD;&#x65B0;&#x5BFC;&#x51FA;</h2>
<p>&#x6211;&#x4EEC;&#x7ECF;&#x5E38;&#x4F1A;&#x53BB;&#x6269;&#x5C55;&#x5176;&#x5B83;&#x6A21;&#x5757;&#xFF0C;&#x5E76;&#x4E14;&#x53EA;&#x5BFC;&#x51FA;&#x90A3;&#x4E2A;&#x6A21;&#x5757;&#x7684;&#x90E8;&#x5206;&#x5185;&#x5BB9;&#x3002;
&#x91CD;&#x65B0;&#x5BFC;&#x51FA;&#x529F;&#x80FD;&#x5E76;&#x4E0D;&#x4F1A;&#x5728;&#x5F53;&#x524D;&#x6A21;&#x5757;&#x5BFC;&#x5165;&#x90A3;&#x4E2A;&#x6A21;&#x5757;&#x6216;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x3002;</p>
<h5 id="parseintbasedzipcodevalidatorts">ParseIntBasedZipCodeValidator.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> ParseIntBasedZipCodeValidator {
    isAcceptable(s: <span class="hljs-built_in">string</span>) {
        <span class="hljs-keyword">return</span> s.length === <span class="hljs-number">5</span> &amp;&amp; <span class="hljs-built_in">parseInt</span>(s).toString() === s;
    }
}

<span class="hljs-comment">// &#x5BFC;&#x51FA;&#x539F;&#x5148;&#x7684;&#x9A8C;&#x8BC1;&#x5668;&#x4F46;&#x505A;&#x4E86;&#x91CD;&#x547D;&#x540D;</span>
<span class="hljs-keyword">export</span> {ZipCodeValidator as RegExpBasedZipCodeValidator} from <span class="hljs-string">&quot;./ZipCodeValidator&quot;</span>;
</code></pre>
<p>&#x6216;&#x8005;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x53EF;&#x4EE5;&#x5305;&#x88F9;&#x591A;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;&#x5E76;&#x628A;&#x4ED6;&#x4EEC;&#x5BFC;&#x51FA;&#x7684;&#x5185;&#x5BB9;&#x8054;&#x5408;&#x5728;&#x4E00;&#x8D77;&#x901A;&#x8FC7;&#x8BED;&#x6CD5;&#xFF1A;<code>export * from &quot;module&quot;</code>&#x3002;</p>
<h5 id="allvalidatorsts">AllValidators.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> * from <span class="hljs-string">&quot;./StringValidator&quot;</span>; <span class="hljs-comment">// exports interface StringValidator</span>
<span class="hljs-keyword">export</span> * from <span class="hljs-string">&quot;./LettersOnlyValidator&quot;</span>; <span class="hljs-comment">// exports class LettersOnlyValidator</span>
<span class="hljs-keyword">export</span> * from <span class="hljs-string">&quot;./ZipCodeValidator&quot;</span>;  <span class="hljs-comment">// exports class ZipCodeValidator</span>
</code></pre>
<h1 id="&#x5BFC;&#x5165;"><a name="import"></a>&#x5BFC;&#x5165;</h1>
<p>&#x6A21;&#x5757;&#x7684;&#x5BFC;&#x5165;&#x64CD;&#x4F5C;&#x4E0E;&#x5BFC;&#x51FA;&#x4E00;&#x6837;&#x7B80;&#x5355;&#x3002;
&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x4EE5;&#x4E0B;<code>import</code>&#x5F62;&#x5F0F;&#x4E4B;&#x4E00;&#x6765;&#x5BFC;&#x5165;&#x5176;&#x5B83;&#x6A21;&#x5757;&#x4E2D;&#x7684;&#x5BFC;&#x51FA;&#x5185;&#x5BB9;&#x3002;</p>
<h2 id="&#x5BFC;&#x5165;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x4E2D;&#x7684;&#x67D0;&#x4E2A;&#x5BFC;&#x51FA;&#x5185;&#x5BB9;">&#x5BFC;&#x5165;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x4E2D;&#x7684;&#x67D0;&#x4E2A;&#x5BFC;&#x51FA;&#x5185;&#x5BB9;</h2>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { ZipCodeValidator } from <span class="hljs-string">&quot;./ZipCodeValidator&quot;</span>;

<span class="hljs-keyword">let</span> myValidator = <span class="hljs-keyword">new</span> ZipCodeValidator();
</code></pre>
<p>&#x53EF;&#x4EE5;&#x5BF9;&#x5BFC;&#x5165;&#x5185;&#x5BB9;&#x91CD;&#x547D;&#x540D;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { ZipCodeValidator as ZCV } from <span class="hljs-string">&quot;./ZipCodeValidator&quot;</span>;
<span class="hljs-keyword">let</span> myValidator = <span class="hljs-keyword">new</span> ZCV();
</code></pre>
<h2 id="&#x5C06;&#x6574;&#x4E2A;&#x6A21;&#x5757;&#x5BFC;&#x5165;&#x5230;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#xFF0C;&#x5E76;&#x901A;&#x8FC7;&#x5B83;&#x6765;&#x8BBF;&#x95EE;&#x6A21;&#x5757;&#x7684;&#x5BFC;&#x51FA;&#x90E8;&#x5206;">&#x5C06;&#x6574;&#x4E2A;&#x6A21;&#x5757;&#x5BFC;&#x5165;&#x5230;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#xFF0C;&#x5E76;&#x901A;&#x8FC7;&#x5B83;&#x6765;&#x8BBF;&#x95EE;&#x6A21;&#x5757;&#x7684;&#x5BFC;&#x51FA;&#x90E8;&#x5206;</h2>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> * as validator from <span class="hljs-string">&quot;./ZipCodeValidator&quot;</span>;
<span class="hljs-keyword">let</span> myValidator = <span class="hljs-keyword">new</span> validator.ZipCodeValidator();
</code></pre>
<h2 id="&#x5177;&#x6709;&#x526F;&#x4F5C;&#x7528;&#x7684;&#x5BFC;&#x5165;&#x6A21;&#x5757;">&#x5177;&#x6709;&#x526F;&#x4F5C;&#x7528;&#x7684;&#x5BFC;&#x5165;&#x6A21;&#x5757;</h2>
<p>&#x5C3D;&#x7BA1;&#x4E0D;&#x63A8;&#x8350;&#x8FD9;&#x4E48;&#x505A;&#xFF0C;&#x4E00;&#x4E9B;&#x6A21;&#x5757;&#x4F1A;&#x8BBE;&#x7F6E;&#x4E00;&#x4E9B;&#x5168;&#x5C40;&#x72B6;&#x6001;&#x4F9B;&#x5176;&#x5B83;&#x6A21;&#x5757;&#x4F7F;&#x7528;&#x3002;
&#x8FD9;&#x4E9B;&#x6A21;&#x5757;&#x53EF;&#x80FD;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x7684;&#x5BFC;&#x51FA;&#x6216;&#x7528;&#x6237;&#x6839;&#x672C;&#x5C31;&#x4E0D;&#x5173;&#x6CE8;&#x5B83;&#x7684;&#x5BFC;&#x51FA;&#x3002;
&#x4F7F;&#x7528;&#x4E0B;&#x9762;&#x7684;&#x65B9;&#x6CD5;&#x6765;&#x5BFC;&#x5165;&#x8FD9;&#x7C7B;&#x6A21;&#x5757;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> <span class="hljs-string">&quot;./my-module.js&quot;</span>;
</code></pre>
<h1 id="&#x9ED8;&#x8BA4;&#x5BFC;&#x51FA;">&#x9ED8;&#x8BA4;&#x5BFC;&#x51FA;</h1>
<p>&#x6BCF;&#x4E2A;&#x6A21;&#x5757;&#x90FD;&#x53EF;&#x4EE5;&#x6709;&#x4E00;&#x4E2A;<code>default</code>&#x5BFC;&#x51FA;&#x3002;
&#x9ED8;&#x8BA4;&#x5BFC;&#x51FA;&#x4F7F;&#x7528;<code>default</code>&#x5173;&#x952E;&#x5B57;&#x6807;&#x8BB0;&#xFF1B;&#x5E76;&#x4E14;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x53EA;&#x80FD;&#x591F;&#x6709;&#x4E00;&#x4E2A;<code>default</code>&#x5BFC;&#x51FA;&#x3002;
&#x9700;&#x8981;&#x4F7F;&#x7528;&#x4E00;&#x79CD;&#x7279;&#x6B8A;&#x7684;&#x5BFC;&#x5165;&#x5F62;&#x5F0F;&#x6765;&#x5BFC;&#x5165;<code>default</code>&#x5BFC;&#x51FA;&#x3002;</p>
<p><code>default</code>&#x5BFC;&#x51FA;&#x5341;&#x5206;&#x4FBF;&#x5229;&#x3002;
&#x6BD4;&#x5982;&#xFF0C;&#x50CF;JQuery&#x8FD9;&#x6837;&#x7684;&#x7C7B;&#x5E93;&#x53EF;&#x80FD;&#x6709;&#x4E00;&#x4E2A;&#x9ED8;&#x8BA4;&#x5BFC;&#x51FA;<code>jQuery</code>&#x6216;<code>$</code>&#xFF0C;&#x5E76;&#x4E14;&#x6211;&#x4EEC;&#x57FA;&#x672C;&#x4E0A;&#x4E5F;&#x4F1A;&#x4F7F;&#x7528;&#x540C;&#x6837;&#x7684;&#x540D;&#x5B57;<code>jQuery</code>&#x6216;<code>$</code>&#x5BFC;&#x51FA;JQuery&#x3002;</p>
<h5 id="jquerydts">JQuery.d.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">let</span> $: JQuery;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> $;
</code></pre>
<h5 id="appts">App.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> $ from <span class="hljs-string">&quot;JQuery&quot;</span>;

$(<span class="hljs-string">&quot;button.continue&quot;</span>).html( <span class="hljs-string">&quot;Next Step...&quot;</span> );
</code></pre>
<p>&#x7C7B;&#x548C;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x88AB;&#x6807;&#x8BB0;&#x4E3A;&#x9ED8;&#x8BA4;&#x5BFC;&#x51FA;&#x3002;
&#x6807;&#x8BB0;&#x4E3A;&#x9ED8;&#x8BA4;&#x5BFC;&#x51FA;&#x7684;&#x7C7B;&#x548C;&#x51FD;&#x6570;&#x7684;&#x540D;&#x5B57;&#x662F;&#x53EF;&#x4EE5;&#x7701;&#x7565;&#x7684;&#x3002;</p>
<h5 id="zipcodevalidatorts">ZipCodeValidator.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-keyword">class</span> ZipCodeValidator {
    <span class="hljs-keyword">static</span> numberRegexp = <span class="hljs-regexp">/^[0-9]+$/</span>;
    isAcceptable(s: <span class="hljs-built_in">string</span>) {
        <span class="hljs-keyword">return</span> s.length === <span class="hljs-number">5</span> &amp;&amp; ZipCodeValidator.numberRegexp.test(s);
    }
}
</code></pre>
<h5 id="testts">Test.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> validator from <span class="hljs-string">&quot;./ZipCodeValidator&quot;</span>;

<span class="hljs-keyword">let</span> myValidator = <span class="hljs-keyword">new</span> validator();
</code></pre>
<p>&#x6216;&#x8005;</p>
<h5 id="staticzipcodevalidatorts">StaticZipCodeValidator.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">const</span> numberRegexp = <span class="hljs-regexp">/^[0-9]+$/</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">s: <span class="hljs-built_in">string</span></span>) </span>{
    <span class="hljs-keyword">return</span> s.length === <span class="hljs-number">5</span> &amp;&amp; numberRegexp.test(s);
}
</code></pre>
<h5 id="testts">Test.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> validate from <span class="hljs-string">&quot;./StaticZipCodeValidator&quot;</span>;

<span class="hljs-keyword">let</span> strings = [<span class="hljs-string">&quot;Hello&quot;</span>, <span class="hljs-string">&quot;98052&quot;</span>, <span class="hljs-string">&quot;101&quot;</span>];

<span class="hljs-comment">// Use function validate</span>
strings.forEach(s =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`&quot;<span class="hljs-subst">${s}</span>&quot; <span class="hljs-subst">${validate(s) ? &quot; matches&quot; : &quot; does not match&quot;}</span>`</span>);
});
</code></pre>
<p><code>default</code>&#x5BFC;&#x51FA;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x503C;</p>
<h5 id="onetwothreets">OneTwoThree.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-string">&quot;123&quot;</span>;
</code></pre>
<h5 id="logts">Log.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> num from <span class="hljs-string">&quot;./OneTwoThree&quot;</span>;

<span class="hljs-built_in">console</span>.log(num); <span class="hljs-comment">// &quot;123&quot;</span>
</code></pre>
<h1 id="export--&#x548C;-import--require"><code>export =</code> &#x548C; <code>import = require()</code></h1>
<p>CommonJS&#x548C;AMD&#x7684;&#x73AF;&#x5883;&#x91CC;&#x90FD;&#x6709;&#x4E00;&#x4E2A;<code>exports</code>&#x53D8;&#x91CF;&#xFF0C;&#x8FD9;&#x4E2A;&#x53D8;&#x91CF;&#x5305;&#x542B;&#x4E86;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x7684;&#x6240;&#x6709;&#x5BFC;&#x51FA;&#x5185;&#x5BB9;&#x3002;</p>
<p>CommonJS&#x548C;AMD&#x7684;<code>exports</code>&#x90FD;&#x53EF;&#x4EE5;&#x88AB;&#x8D4B;&#x503C;&#x4E3A;&#x4E00;&#x4E2A;<code>&#x5BF9;&#x8C61;</code>, &#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#x5176;&#x4F5C;&#x7528;&#x5C31;&#x7C7B;&#x4F3C;&#x4E8E; es6 &#x8BED;&#x6CD5;&#x91CC;&#x7684;&#x9ED8;&#x8BA4;&#x5BFC;&#x51FA;&#xFF0C;&#x5373; <code>export default</code>&#x8BED;&#x6CD5;&#x4E86;&#x3002;&#x867D;&#x7136;&#x4F5C;&#x7528;&#x76F8;&#x4F3C;&#xFF0C;&#x4F46;&#x662F; <code>export default</code> &#x8BED;&#x6CD5;&#x5E76;&#x4E0D;&#x80FD;&#x517C;&#x5BB9;CommonJS&#x548C;AMD&#x7684;<code>exports</code>&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x652F;&#x6301;CommonJS&#x548C;AMD&#x7684;<code>exports</code>, TypeScript&#x63D0;&#x4F9B;&#x4E86;<code>export =</code>&#x8BED;&#x6CD5;&#x3002;</p>
<p><code>export =</code>&#x8BED;&#x6CD5;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x7684;&#x5BFC;&#x51FA;<code>&#x5BF9;&#x8C61;</code>&#x3002;
&#x8FD9;&#x91CC;&#x7684;<code>&#x5BF9;&#x8C61;</code>&#x4E00;&#x8BCD;&#x6307;&#x7684;&#x662F;&#x7C7B;&#xFF0C;&#x63A5;&#x53E3;&#xFF0C;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#xFF0C;&#x51FD;&#x6570;&#x6216;&#x679A;&#x4E3E;&#x3002;</p>
<p>&#x82E5;&#x4F7F;&#x7528;<code>export =</code>&#x5BFC;&#x51FA;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;&#x5219;&#x5FC5;&#x987B;&#x4F7F;&#x7528;TypeScript&#x7684;&#x7279;&#x5B9A;&#x8BED;&#x6CD5;<code>import module = require(&quot;module&quot;)</code>&#x6765;&#x5BFC;&#x5165;&#x6B64;&#x6A21;&#x5757;&#x3002;</p>
<h5 id="zipcodevalidatorts">ZipCodeValidator.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">let</span> numberRegexp = <span class="hljs-regexp">/^[0-9]+$/</span>;
<span class="hljs-keyword">class</span> ZipCodeValidator {
    isAcceptable(s: <span class="hljs-built_in">string</span>) {
        <span class="hljs-keyword">return</span> s.length === <span class="hljs-number">5</span> &amp;&amp; numberRegexp.test(s);
    }
}
<span class="hljs-keyword">export</span> = ZipCodeValidator;
</code></pre>
<h5 id="testts">Test.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> zip = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;./ZipCodeValidator&quot;</span>);

<span class="hljs-comment">// Some samples to try</span>
<span class="hljs-keyword">let</span> strings = [<span class="hljs-string">&quot;Hello&quot;</span>, <span class="hljs-string">&quot;98052&quot;</span>, <span class="hljs-string">&quot;101&quot;</span>];

<span class="hljs-comment">// Validators to use</span>
<span class="hljs-keyword">let</span> validator = <span class="hljs-keyword">new</span> zip();

<span class="hljs-comment">// Show whether each string passed each validator</span>
strings.forEach(s =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`&quot;<span class="hljs-subst">${ s }</span>&quot; - <span class="hljs-subst">${ validator.isAcceptable(s) ? &quot;matches&quot; : &quot;does not match&quot; }</span>`</span>);
});
</code></pre>
<h1 id="&#x751F;&#x6210;&#x6A21;&#x5757;&#x4EE3;&#x7801;">&#x751F;&#x6210;&#x6A21;&#x5757;&#x4EE3;&#x7801;</h1>
<p>&#x6839;&#x636E;&#x7F16;&#x8BD1;&#x65F6;&#x6307;&#x5B9A;&#x7684;&#x6A21;&#x5757;&#x76EE;&#x6807;&#x53C2;&#x6570;&#xFF0C;&#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x751F;&#x6210;&#x76F8;&#x5E94;&#x7684;&#x4F9B;Node.js (<a href="http://wiki.commonjs.org/wiki/CommonJS" target="_blank">CommonJS</a>)&#xFF0C;Require.js (<a href="https://github.com/amdjs/amdjs-api/wiki/AMD" target="_blank">AMD</a>)&#xFF0C;<a href="https://github.com/umdjs/umd" target="_blank">UMD</a>, <a href="https://github.com/systemjs/systemjs" target="_blank">SystemJS</a>&#x6216;<a href="http://www.ecma-international.org/ecma-262/6.0/#sec-modules" target="_blank">ECMAScript 2015 native modules</a> (ES6)&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x7CFB;&#x7EDF;&#x4F7F;&#x7528;&#x7684;&#x4EE3;&#x7801;&#x3002;
&#x60F3;&#x8981;&#x4E86;&#x89E3;&#x751F;&#x6210;&#x4EE3;&#x7801;&#x4E2D;<code>define</code>&#xFF0C;<code>require</code> &#x548C; <code>register</code>&#x7684;&#x610F;&#x4E49;&#xFF0C;&#x8BF7;&#x53C2;&#x8003;&#x76F8;&#x5E94;&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#x7684;&#x6587;&#x6863;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x8BF4;&#x660E;&#x4E86;&#x5BFC;&#x5165;&#x5BFC;&#x51FA;&#x8BED;&#x53E5;&#x91CC;&#x4F7F;&#x7528;&#x7684;&#x540D;&#x5B57;&#x662F;&#x600E;&#x4E48;&#x8F6C;&#x6362;&#x4E3A;&#x76F8;&#x5E94;&#x7684;&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#x4EE3;&#x7801;&#x7684;&#x3002;</p>
<h5 id="simplemodulets">SimpleModule.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> m = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;mod&quot;</span>);
<span class="hljs-keyword">export</span> <span class="hljs-keyword">let</span> t = m.something + <span class="hljs-number">1</span>;
</code></pre>
<h5 id="amd--requirejs-simplemodulejs">AMD / RequireJS SimpleModule.js</h5>
<pre><code class="lang-js">define([<span class="hljs-string">&quot;require&quot;</span>, <span class="hljs-string">&quot;exports&quot;</span>, <span class="hljs-string">&quot;./mod&quot;</span>], <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">require, exports, mod_1</span>) </span>{
    exports.t = mod_1.something + <span class="hljs-number">1</span>;
});
</code></pre>
<h5 id="commonjs--node-simplemodulejs">CommonJS / Node SimpleModule.js</h5>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> mod_1 = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;./mod&quot;</span>);
exports.t = mod_1.something + <span class="hljs-number">1</span>;
</code></pre>
<h5 id="umd-simplemodulejs">UMD SimpleModule.js</h5>
<pre><code class="lang-js">(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">factory</span>) </span>{
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> <span class="hljs-built_in">module</span> === <span class="hljs-string">&quot;object&quot;</span> &amp;&amp; <span class="hljs-keyword">typeof</span> <span class="hljs-built_in">module</span>.exports === <span class="hljs-string">&quot;object&quot;</span>) {
        <span class="hljs-keyword">let</span> v = factory(<span class="hljs-built_in">require</span>, exports); <span class="hljs-keyword">if</span> (v !== <span class="hljs-literal">undefined</span>) <span class="hljs-built_in">module</span>.exports = v;
    }
    <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> define === <span class="hljs-string">&quot;function&quot;</span> &amp;&amp; define.amd) {
        define([<span class="hljs-string">&quot;require&quot;</span>, <span class="hljs-string">&quot;exports&quot;</span>, <span class="hljs-string">&quot;./mod&quot;</span>], factory);
    }
})(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">require, exports</span>) </span>{
    <span class="hljs-keyword">let</span> mod_1 = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;./mod&quot;</span>);
    exports.t = mod_1.something + <span class="hljs-number">1</span>;
});
</code></pre>
<h5 id="system-simplemodulejs">System SimpleModule.js</h5>
<pre><code class="lang-js">System.register([<span class="hljs-string">&quot;./mod&quot;</span>], <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">exports_1</span>) </span>{
    <span class="hljs-keyword">let</span> mod_1;
    <span class="hljs-keyword">let</span> t;
    <span class="hljs-keyword">return</span> {
        setters:[
            <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">mod_1_1</span>) </span>{
                mod_1 = mod_1_1;
            }],
        execute: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
            exports_1(<span class="hljs-string">&quot;t&quot;</span>, t = mod_1.something + <span class="hljs-number">1</span>);
        }
    }
});
</code></pre>
<h5 id="native-ecmascript-2015-modules-simplemodulejs">Native ECMAScript 2015 modules SimpleModule.js</h5>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { something } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;./mod&quot;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">let</span> t = something + <span class="hljs-number">1</span>;
</code></pre>
<h1 id="&#x7B80;&#x5355;&#x793A;&#x4F8B;">&#x7B80;&#x5355;&#x793A;&#x4F8B;</h1>
<p>&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x6765;&#x6574;&#x7406;&#x4E00;&#x4E0B;&#x524D;&#x9762;&#x7684;&#x9A8C;&#x8BC1;&#x5668;&#x5B9E;&#x73B0;&#xFF0C;&#x6BCF;&#x4E2A;&#x6A21;&#x5757;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x547D;&#x540D;&#x7684;&#x5BFC;&#x51FA;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x7F16;&#x8BD1;&#xFF0C;&#x6211;&#x4EEC;&#x5FC5;&#x9700;&#x8981;&#x5728;&#x547D;&#x4EE4;&#x884C;&#x4E0A;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x76EE;&#x6807;&#x3002;&#x5BF9;&#x4E8E;Node.js&#x6765;&#x8BF4;&#xFF0C;&#x4F7F;&#x7528;<code>--module commonjs</code>&#xFF1B;
&#x5BF9;&#x4E8E;Require.js&#x6765;&#x8BF4;&#xFF0C;&#x4F7F;&#x7528;<code>--module amd</code>&#x3002;&#x6BD4;&#x5982;&#xFF1A;</p>
<pre><code class="lang-Shell">tsc --module commonjs Test.ts
</code></pre>
<p>&#x7F16;&#x8BD1;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x6BCF;&#x4E2A;&#x6A21;&#x5757;&#x4F1A;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x5355;&#x72EC;&#x7684;<code>.js</code>&#x6587;&#x4EF6;&#x3002;
&#x597D;&#x6BD4;&#x4F7F;&#x7528;&#x4E86;reference&#x6807;&#x7B7E;&#xFF0C;&#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x6839;&#x636E;<code>import</code>&#x8BED;&#x53E5;&#x7F16;&#x8BD1;&#x76F8;&#x5E94;&#x7684;&#x6587;&#x4EF6;&#x3002;</p>
<h5 id="validationts">Validation.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> <span class="hljs-keyword">interface</span> StringValidator {
    isAcceptable(s: <span class="hljs-built_in">string</span>): <span class="hljs-built_in">boolean</span>;
}
</code></pre>
<h5 id="lettersonlyvalidatorts">LettersOnlyValidator.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { StringValidator } from <span class="hljs-string">&quot;./Validation&quot;</span>;

<span class="hljs-keyword">const</span> lettersRegexp = <span class="hljs-regexp">/^[A-Za-z]+$/</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> LettersOnlyValidator <span class="hljs-keyword">implements</span> StringValidator {
    isAcceptable(s: <span class="hljs-built_in">string</span>) {
        <span class="hljs-keyword">return</span> lettersRegexp.test(s);
    }
}
</code></pre>
<h5 id="zipcodevalidatorts">ZipCodeValidator.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { StringValidator } from <span class="hljs-string">&quot;./Validation&quot;</span>;

<span class="hljs-keyword">const</span> numberRegexp = <span class="hljs-regexp">/^[0-9]+$/</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> ZipCodeValidator <span class="hljs-keyword">implements</span> StringValidator {
    isAcceptable(s: <span class="hljs-built_in">string</span>) {
        <span class="hljs-keyword">return</span> s.length === <span class="hljs-number">5</span> &amp;&amp; numberRegexp.test(s);
    }
}
</code></pre>
<h5 id="testts">Test.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { StringValidator } from <span class="hljs-string">&quot;./Validation&quot;</span>;
<span class="hljs-keyword">import</span> { ZipCodeValidator } from <span class="hljs-string">&quot;./ZipCodeValidator&quot;</span>;
<span class="hljs-keyword">import</span> { LettersOnlyValidator } from <span class="hljs-string">&quot;./LettersOnlyValidator&quot;</span>;

<span class="hljs-comment">// Some samples to try</span>
<span class="hljs-keyword">let</span> strings = [<span class="hljs-string">&quot;Hello&quot;</span>, <span class="hljs-string">&quot;98052&quot;</span>, <span class="hljs-string">&quot;101&quot;</span>];

<span class="hljs-comment">// Validators to use</span>
<span class="hljs-keyword">let</span> validators: { [s: <span class="hljs-built_in">string</span>]: StringValidator; } = {};
validators[<span class="hljs-string">&quot;ZIP code&quot;</span>] = <span class="hljs-keyword">new</span> ZipCodeValidator();
validators[<span class="hljs-string">&quot;Letters only&quot;</span>] = <span class="hljs-keyword">new</span> LettersOnlyValidator();

<span class="hljs-comment">// Show whether each string passed each validator</span>
strings.forEach(s =&gt; {
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> name <span class="hljs-keyword">in</span> validators) {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`&quot;<span class="hljs-subst">${ s }</span>&quot; - <span class="hljs-subst">${ validators[name].isAcceptable(s) ? &quot;matches&quot; : &quot;does not match&quot; }</span> <span class="hljs-subst">${ name }</span>`</span>);
    }
});
</code></pre>
<h1 id="&#x53EF;&#x9009;&#x7684;&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x548C;&#x5176;&#x5B83;&#x9AD8;&#x7EA7;&#x52A0;&#x8F7D;&#x573A;&#x666F;">&#x53EF;&#x9009;&#x7684;&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x548C;&#x5176;&#x5B83;&#x9AD8;&#x7EA7;&#x52A0;&#x8F7D;&#x573A;&#x666F;</h1>
<p>&#x6709;&#x65F6;&#x5019;&#xFF0C;&#x4F60;&#x53EA;&#x60F3;&#x5728;&#x67D0;&#x79CD;&#x6761;&#x4EF6;&#x4E0B;&#x624D;&#x52A0;&#x8F7D;&#x67D0;&#x4E2A;&#x6A21;&#x5757;&#x3002;
&#x5728;TypeScript&#x91CC;&#xFF0C;&#x4F7F;&#x7528;&#x4E0B;&#x9762;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x5B9E;&#x73B0;&#x5B83;&#x548C;&#x5176;&#x5B83;&#x7684;&#x9AD8;&#x7EA7;&#x52A0;&#x8F7D;&#x573A;&#x666F;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8C03;&#x7528;&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#x5E76;&#x4E14;&#x53EF;&#x4EE5;&#x4FDD;&#x8BC1;&#x7C7B;&#x578B;&#x5B8C;&#x5168;&#x3002;</p>
<p>&#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x68C0;&#x6D4B;&#x662F;&#x5426;&#x6BCF;&#x4E2A;&#x6A21;&#x5757;&#x90FD;&#x4F1A;&#x5728;&#x751F;&#x6210;&#x7684;JavaScript&#x4E2D;&#x7528;&#x5230;&#x3002;
&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x6807;&#x8BC6;&#x7B26;&#x53EA;&#x5728;&#x7C7B;&#x578B;&#x6CE8;&#x89E3;&#x90E8;&#x5206;&#x4F7F;&#x7528;&#xFF0C;&#x5E76;&#x4E14;&#x5B8C;&#x5168;&#x6CA1;&#x6709;&#x5728;&#x8868;&#x8FBE;&#x5F0F;&#x4E2D;&#x4F7F;&#x7528;&#x65F6;&#xFF0C;&#x5C31;&#x4E0D;&#x4F1A;&#x751F;&#x6210;<code>require</code>&#x8FD9;&#x4E2A;&#x6A21;&#x5757;&#x7684;&#x4EE3;&#x7801;&#x3002;
&#x7701;&#x7565;&#x6389;&#x6CA1;&#x6709;&#x7528;&#x5230;&#x7684;&#x5F15;&#x7528;&#x5BF9;&#x6027;&#x80FD;&#x63D0;&#x5347;&#x662F;&#x5F88;&#x6709;&#x76CA;&#x7684;&#xFF0C;&#x5E76;&#x540C;&#x65F6;&#x63D0;&#x4F9B;&#x4E86;&#x9009;&#x62E9;&#x6027;&#x52A0;&#x8F7D;&#x6A21;&#x5757;&#x7684;&#x80FD;&#x529B;&#x3002;</p>
<p>&#x8FD9;&#x79CD;&#x6A21;&#x5F0F;&#x7684;&#x6838;&#x5FC3;&#x662F;<code>import id = require(&quot;...&quot;)</code>&#x8BED;&#x53E5;&#x53EF;&#x4EE5;&#x8BA9;&#x6211;&#x4EEC;&#x8BBF;&#x95EE;&#x6A21;&#x5757;&#x5BFC;&#x51FA;&#x7684;&#x7C7B;&#x578B;&#x3002;
&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#x4F1A;&#x88AB;&#x52A8;&#x6001;&#x8C03;&#x7528;&#xFF08;&#x901A;&#x8FC7;<code>require</code>&#xFF09;&#xFF0C;&#x5C31;&#x50CF;&#x4E0B;&#x9762;<code>if</code>&#x4EE3;&#x7801;&#x5757;&#x91CC;&#x90A3;&#x6837;&#x3002;
&#x5B83;&#x5229;&#x7528;&#x4E86;&#x7701;&#x7565;&#x5F15;&#x7528;&#x7684;&#x4F18;&#x5316;&#xFF0C;&#x6240;&#x4EE5;&#x6A21;&#x5757;&#x53EA;&#x5728;&#x88AB;&#x9700;&#x8981;&#x65F6;&#x52A0;&#x8F7D;&#x3002;
&#x4E3A;&#x4E86;&#x8BA9;&#x8FD9;&#x4E2A;&#x6A21;&#x5757;&#x5DE5;&#x4F5C;&#xFF0C;&#x4E00;&#x5B9A;&#x8981;&#x6CE8;&#x610F;<code>import</code>&#x5B9A;&#x4E49;&#x7684;&#x6807;&#x8BC6;&#x7B26;&#x53EA;&#x80FD;&#x5728;&#x8868;&#x793A;&#x7C7B;&#x578B;&#x5904;&#x4F7F;&#x7528;&#xFF08;&#x4E0D;&#x80FD;&#x5728;&#x4F1A;&#x8F6C;&#x6362;&#x6210;JavaScript&#x7684;&#x5730;&#x65B9;&#xFF09;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x786E;&#x4FDD;&#x7C7B;&#x578B;&#x5B89;&#x5168;&#x6027;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>typeof</code>&#x5173;&#x952E;&#x5B57;&#x3002;
<code>typeof</code>&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x5F53;&#x5728;&#x8868;&#x793A;&#x7C7B;&#x578B;&#x7684;&#x5730;&#x65B9;&#x4F7F;&#x7528;&#x65F6;&#xFF0C;&#x4F1A;&#x5F97;&#x51FA;&#x4E00;&#x4E2A;&#x7C7B;&#x578B;&#x503C;&#xFF0C;&#x8FD9;&#x91CC;&#x5C31;&#x8868;&#x793A;&#x6A21;&#x5757;&#x7684;&#x7C7B;&#x578B;&#x3002;</p>
<h5 id="&#x793A;&#x4F8B;&#xFF1A;nodejs&#x91CC;&#x7684;&#x52A8;&#x6001;&#x6A21;&#x5757;&#x52A0;&#x8F7D;">&#x793A;&#x4F8B;&#xFF1A;Node.js&#x91CC;&#x7684;&#x52A8;&#x6001;&#x6A21;&#x5757;&#x52A0;&#x8F7D;</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">require</span>(<span class="hljs-params">moduleName: <span class="hljs-built_in">string</span></span>): <span class="hljs-title">any</span></span>;

<span class="hljs-keyword">import</span> { ZipCodeValidator as Zip } from <span class="hljs-string">&quot;./ZipCodeValidator&quot;</span>;

<span class="hljs-keyword">if</span> (needZipValidation) {
    <span class="hljs-keyword">let</span> ZipCodeValidator: <span class="hljs-keyword">typeof</span> Zip = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;./ZipCodeValidator&quot;</span>);
    <span class="hljs-keyword">let</span> validator = <span class="hljs-keyword">new</span> ZipCodeValidator();
    <span class="hljs-keyword">if</span> (validator.isAcceptable(<span class="hljs-string">&quot;...&quot;</span>)) { <span class="hljs-comment">/* ... */</span> }
}
</code></pre>
<h5 id="&#x793A;&#x4F8B;&#xFF1A;requirejs&#x91CC;&#x7684;&#x52A8;&#x6001;&#x6A21;&#x5757;&#x52A0;&#x8F7D;">&#x793A;&#x4F8B;&#xFF1A;require.js&#x91CC;&#x7684;&#x52A8;&#x6001;&#x6A21;&#x5757;&#x52A0;&#x8F7D;</h5>
<pre><code class="lang-ts">declare function require(moduleNames: string[], onLoad: (...args: any[]) =&gt; void): void;

import * as Zip from &quot;./ZipCodeValidator&quot;;

if (needZipValidation) {
    require([&quot;./ZipCodeValidator&quot;], (ZipCodeValidator: typeof Zip) =&gt; {
        let validator = new ZipCodeValidator.ZipCodeValidator();
        if (validator.isAcceptable(&quot;...&quot;)) { /* ... */ }
    });
}
</code></pre>
<h5 id="&#x793A;&#x4F8B;&#xFF1A;systemjs&#x91CC;&#x7684;&#x52A8;&#x6001;&#x6A21;&#x5757;&#x52A0;&#x8F7D;">&#x793A;&#x4F8B;&#xFF1A;System.js&#x91CC;&#x7684;&#x52A8;&#x6001;&#x6A21;&#x5757;&#x52A0;&#x8F7D;</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">const</span> System: <span class="hljs-built_in">any</span>;

<span class="hljs-keyword">import</span> { ZipCodeValidator as Zip } from <span class="hljs-string">&quot;./ZipCodeValidator&quot;</span>;

<span class="hljs-keyword">if</span> (needZipValidation) {
    System.import(<span class="hljs-string">&quot;./ZipCodeValidator&quot;</span>).then((ZipCodeValidator: <span class="hljs-keyword">typeof</span> Zip) =&gt; {
        <span class="hljs-keyword">var</span> x = <span class="hljs-keyword">new</span> ZipCodeValidator();
        <span class="hljs-keyword">if</span> (x.isAcceptable(<span class="hljs-string">&quot;...&quot;</span>)) { <span class="hljs-comment">/* ... */</span> }
    });
}
</code></pre>
<h1 id="&#x4F7F;&#x7528;&#x5176;&#x5B83;&#x7684;javascript&#x5E93;">&#x4F7F;&#x7528;&#x5176;&#x5B83;&#x7684;JavaScript&#x5E93;</h1>
<p>&#x8981;&#x60F3;&#x63CF;&#x8FF0;&#x975E;TypeScript&#x7F16;&#x5199;&#x7684;&#x7C7B;&#x5E93;&#x7684;&#x7C7B;&#x578B;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x58F0;&#x660E;&#x7C7B;&#x5E93;&#x6240;&#x66B4;&#x9732;&#x51FA;&#x7684;API&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x53EB;&#x5B83;&#x58F0;&#x660E;&#x56E0;&#x4E3A;&#x5B83;&#x4E0D;&#x662F;&#x201C;&#x5916;&#x90E8;&#x7A0B;&#x5E8F;&#x201D;&#x7684;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#x3002;
&#x5B83;&#x4EEC;&#x901A;&#x5E38;&#x662F;&#x5728;<code>.d.ts</code>&#x6587;&#x4EF6;&#x91CC;&#x5B9A;&#x4E49;&#x7684;&#x3002;
&#x5982;&#x679C;&#x4F60;&#x719F;&#x6089;C/C++&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x628A;&#x5B83;&#x4EEC;&#x5F53;&#x505A;<code>.h</code>&#x6587;&#x4EF6;&#x3002;
&#x8BA9;&#x6211;&#x4EEC;&#x770B;&#x4E00;&#x4E9B;&#x4F8B;&#x5B50;&#x3002;</p>
<h2 id="&#x5916;&#x90E8;&#x6A21;&#x5757;">&#x5916;&#x90E8;&#x6A21;&#x5757;</h2>
<p>&#x5728;Node.js&#x91CC;&#x5927;&#x90E8;&#x5206;&#x5DE5;&#x4F5C;&#x662F;&#x901A;&#x8FC7;&#x52A0;&#x8F7D;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x6A21;&#x5757;&#x5B9E;&#x73B0;&#x7684;&#x3002;
&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x9876;&#x7EA7;&#x7684;<code>export</code>&#x58F0;&#x660E;&#x6765;&#x4E3A;&#x6BCF;&#x4E2A;&#x6A21;&#x5757;&#x90FD;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;<code>.d.ts</code>&#x6587;&#x4EF6;&#xFF0C;&#x4F46;&#x6700;&#x597D;&#x8FD8;&#x662F;&#x5199;&#x5728;&#x4E00;&#x4E2A;&#x5927;&#x7684;<code>.d.ts</code>&#x6587;&#x4EF6;&#x91CC;&#x3002;
&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x4E0E;&#x6784;&#x9020;&#x4E00;&#x4E2A;&#x5916;&#x90E8;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x76F8;&#x4F3C;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x4F46;&#x662F;&#x8FD9;&#x91CC;&#x4F7F;&#x7528;<code>module</code>&#x5173;&#x952E;&#x5B57;&#x5E76;&#x4E14;&#x628A;&#x540D;&#x5B57;&#x7528;&#x5F15;&#x53F7;&#x62EC;&#x8D77;&#x6765;&#xFF0C;&#x65B9;&#x4FBF;&#x4E4B;&#x540E;<code>import</code>&#x3002;
&#x4F8B;&#x5982;&#xFF1A;</p>
<h5 id="nodedts-simplified-excerpt">node.d.ts (simplified excerpt)</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">module</span> &quot;url&quot; {
    <span class="hljs-keyword">export</span> <span class="hljs-keyword">interface</span> Url {
        protocol?: <span class="hljs-built_in">string</span>;
        hostname?: <span class="hljs-built_in">string</span>;
        pathname?: <span class="hljs-built_in">string</span>;
    }

    <span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">parse</span>(<span class="hljs-params">urlStr: <span class="hljs-built_in">string</span>, parseQueryString?, slashesDenoteHost?</span>): <span class="hljs-title">Url</span></span>;
}

<span class="hljs-keyword">declare</span> <span class="hljs-keyword">module</span> &quot;path&quot; {
    <span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">normalize</span>(<span class="hljs-params">p: <span class="hljs-built_in">string</span></span>): <span class="hljs-title">string</span></span>;
    <span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">join</span>(<span class="hljs-params">...paths: <span class="hljs-built_in">any</span>[]</span>): <span class="hljs-title">string</span></span>;
    <span class="hljs-keyword">export</span> <span class="hljs-keyword">let</span> sep: <span class="hljs-built_in">string</span>;
}
</code></pre>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;<code>/// &lt;reference&gt;</code> <code>node.d.ts</code>&#x5E76;&#x4E14;&#x4F7F;&#x7528;<code>import url = require(&quot;url&quot;);</code>&#x6216;<code>import * as URL from &quot;url&quot;</code>&#x52A0;&#x8F7D;&#x6A21;&#x5757;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-comment">/// &lt;reference path=&quot;node.d.ts&quot;/&gt;</span>
<span class="hljs-keyword">import</span> * as URL from <span class="hljs-string">&quot;url&quot;</span>;
<span class="hljs-keyword">let</span> myUrl = URL.parse(<span class="hljs-string">&quot;http://www.typescriptlang.org&quot;</span>);
</code></pre>
<h3 id="&#x5916;&#x90E8;&#x6A21;&#x5757;&#x7B80;&#x5199;">&#x5916;&#x90E8;&#x6A21;&#x5757;&#x7B80;&#x5199;</h3>
<p>&#x5047;&#x5982;&#x4F60;&#x4E0D;&#x60F3;&#x5728;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x65B0;&#x6A21;&#x5757;&#x4E4B;&#x524D;&#x82B1;&#x65F6;&#x95F4;&#x53BB;&#x7F16;&#x5199;&#x58F0;&#x660E;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x91C7;&#x7528;&#x58F0;&#x660E;&#x7684;&#x7B80;&#x5199;&#x5F62;&#x5F0F;&#x4EE5;&#x4FBF;&#x80FD;&#x591F;&#x5FEB;&#x901F;&#x4F7F;&#x7528;&#x5B83;&#x3002;</p>
<h5 id="declarationsdts">declarations.d.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">module</span> &quot;hot-new-<span class="hljs-keyword">module</span>&quot;;
</code></pre>
<p>&#x7B80;&#x5199;&#x6A21;&#x5757;&#x91CC;&#x6240;&#x6709;&#x5BFC;&#x51FA;&#x7684;&#x7C7B;&#x578B;&#x5C06;&#x662F;<code>any</code>&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> x, {y} from <span class="hljs-string">&quot;hot-new-module&quot;</span>;
x(y);
</code></pre>
<h3 id="&#x6A21;&#x5757;&#x58F0;&#x660E;&#x901A;&#x914D;&#x7B26;">&#x6A21;&#x5757;&#x58F0;&#x660E;&#x901A;&#x914D;&#x7B26;</h3>
<p>&#x67D0;&#x4E9B;&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#x5982;<a href="https://github.com/systemjs/systemjs/blob/master/docs/overview.md#plugin-syntax" target="_blank">SystemJS</a>
&#x548C;<a href="https://github.com/amdjs/amdjs-api/blob/master/LoaderPlugins.md" target="_blank">AMD</a>&#x652F;&#x6301;&#x5BFC;&#x5165;&#x975E;JavaScript&#x5185;&#x5BB9;&#x3002;
&#x5B83;&#x4EEC;&#x901A;&#x5E38;&#x4F1A;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x524D;&#x7F00;&#x6216;&#x540E;&#x7F00;&#x6765;&#x8868;&#x793A;&#x7279;&#x6B8A;&#x7684;&#x52A0;&#x8F7D;&#x8BED;&#x6CD5;&#x3002;
&#x6A21;&#x5757;&#x58F0;&#x660E;&#x901A;&#x914D;&#x7B26;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x8868;&#x793A;&#x8FD9;&#x4E9B;&#x60C5;&#x51B5;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">module</span> &quot;*!text&quot; {
    <span class="hljs-keyword">const</span> content: <span class="hljs-built_in">string</span>;
    <span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> content;
}
<span class="hljs-comment">// Some do it the other way around.</span>
<span class="hljs-keyword">declare</span> <span class="hljs-keyword">module</span> &quot;json!*&quot; {
    <span class="hljs-keyword">const</span> value: <span class="hljs-built_in">any</span>;
    <span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> value;
}
</code></pre>
<p>&#x73B0;&#x5728;&#x4F60;&#x53EF;&#x4EE5;&#x5C31;&#x5BFC;&#x5165;&#x5339;&#x914D;<code>&quot;*!text&quot;</code>&#x6216;<code>&quot;json!*&quot;</code>&#x7684;&#x5185;&#x5BB9;&#x4E86;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> fileContent from <span class="hljs-string">&quot;./xyz.txt!text&quot;</span>;
<span class="hljs-keyword">import</span> data from <span class="hljs-string">&quot;json!http://example.com/data.json&quot;</span>;
<span class="hljs-built_in">console</span>.log(data, fileContent);
</code></pre>
<h3 id="umd&#x6A21;&#x5757;">UMD&#x6A21;&#x5757;</h3>
<p>&#x6709;&#x4E9B;&#x6A21;&#x5757;&#x88AB;&#x8BBE;&#x8BA1;&#x6210;&#x517C;&#x5BB9;&#x591A;&#x4E2A;&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#xFF0C;&#x6216;&#x8005;&#x4E0D;&#x4F7F;&#x7528;&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x5668;&#xFF08;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF09;&#x3002;
&#x5B83;&#x4EEC;&#x4EE5;<a href="https://github.com/umdjs/umd" target="_blank">UMD</a>&#x6A21;&#x5757;&#x4E3A;&#x4EE3;&#x8868;&#x3002;
&#x8FD9;&#x4E9B;&#x5E93;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5BFC;&#x5165;&#x7684;&#x5F62;&#x5F0F;&#x6216;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x7684;&#x5F62;&#x5F0F;&#x8BBF;&#x95EE;&#x3002;
&#x4F8B;&#x5982;&#xFF1A;</p>
<h5 id="math-libdts">math-lib.d.ts</h5>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">isPrime</span>(<span class="hljs-params">x: <span class="hljs-built_in">number</span></span>): <span class="hljs-title">boolean</span></span>;
<span class="hljs-keyword">export</span> as <span class="hljs-keyword">namespace</span> mathLib;
</code></pre>
<p>&#x4E4B;&#x540E;&#xFF0C;&#x8FD9;&#x4E2A;&#x5E93;&#x53EF;&#x4EE5;&#x5728;&#x67D0;&#x4E2A;&#x6A21;&#x5757;&#x91CC;&#x901A;&#x8FC7;&#x5BFC;&#x5165;&#x6765;&#x4F7F;&#x7528;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { isPrime } from <span class="hljs-string">&quot;math-lib&quot;</span>;
isPrime(<span class="hljs-number">2</span>);
mathLib.isPrime(<span class="hljs-number">2</span>); <span class="hljs-comment">// ERROR: can&apos;t use the global definition from inside a module</span>
</code></pre>
<p>&#x5B83;&#x540C;&#x6837;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x7684;&#x5F62;&#x5F0F;&#x4F7F;&#x7528;&#xFF0C;&#x4F46;&#x53EA;&#x80FD;&#x5728;&#x67D0;&#x4E2A;&#x811A;&#x672C;&#x91CC;&#x3002;
&#xFF08;&#x811A;&#x672C;&#x662F;&#x6307;&#x4E00;&#x4E2A;&#x4E0D;&#x5E26;&#x6709;&#x5BFC;&#x5165;&#x6216;&#x5BFC;&#x51FA;&#x7684;&#x6587;&#x4EF6;&#x3002;&#xFF09;</p>
<pre><code class="lang-ts">mathLib.isPrime(<span class="hljs-number">2</span>);
</code></pre>
<h1 id="&#x521B;&#x5EFA;&#x6A21;&#x5757;&#x7ED3;&#x6784;&#x6307;&#x5BFC;">&#x521B;&#x5EFA;&#x6A21;&#x5757;&#x7ED3;&#x6784;&#x6307;&#x5BFC;</h1>
<h2 id="&#x5C3D;&#x53EF;&#x80FD;&#x5730;&#x5728;&#x9876;&#x5C42;&#x5BFC;&#x51FA;">&#x5C3D;&#x53EF;&#x80FD;&#x5730;&#x5728;&#x9876;&#x5C42;&#x5BFC;&#x51FA;</h2>
<p>&#x7528;&#x6237;&#x5E94;&#x8BE5;&#x66F4;&#x5BB9;&#x6613;&#x5730;&#x4F7F;&#x7528;&#x4F60;&#x6A21;&#x5757;&#x5BFC;&#x51FA;&#x7684;&#x5185;&#x5BB9;&#x3002;
&#x5D4C;&#x5957;&#x5C42;&#x6B21;&#x8FC7;&#x591A;&#x4F1A;&#x53D8;&#x5F97;&#x96BE;&#x4EE5;&#x5904;&#x7406;&#xFF0C;&#x56E0;&#x6B64;&#x4ED4;&#x7EC6;&#x8003;&#x8651;&#x4E00;&#x4E0B;&#x5982;&#x4F55;&#x7EC4;&#x7EC7;&#x4F60;&#x7684;&#x4EE3;&#x7801;&#x3002;</p>
<p>&#x4ECE;&#x4F60;&#x7684;&#x6A21;&#x5757;&#x4E2D;&#x5BFC;&#x51FA;&#x4E00;&#x4E2A;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x589E;&#x52A0;&#x5D4C;&#x5957;&#x7684;&#x4F8B;&#x5B50;&#x3002;
&#x867D;&#x7136;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x6709;&#x65F6;&#x5019;&#x6709;&#x5B83;&#x4EEC;&#x7684;&#x7528;&#x5904;&#xFF0C;&#x5728;&#x4F7F;&#x7528;&#x6A21;&#x5757;&#x7684;&#x65F6;&#x5019;&#x5B83;&#x4EEC;&#x989D;&#x5916;&#x5730;&#x589E;&#x52A0;&#x4E86;&#x4E00;&#x5C42;&#x3002;
&#x8FD9;&#x5BF9;&#x7528;&#x6237;&#x6765;&#x8BF4;&#x662F;&#x5F88;&#x4E0D;&#x4FBF;&#x7684;&#x5E76;&#x4E14;&#x901A;&#x5E38;&#x662F;&#x591A;&#x4F59;&#x7684;&#x3002;</p>
<p>&#x5BFC;&#x51FA;&#x7C7B;&#x7684;&#x9759;&#x6001;&#x65B9;&#x6CD5;&#x4E5F;&#x6709;&#x540C;&#x6837;&#x7684;&#x95EE;&#x9898; - &#x8FD9;&#x4E2A;&#x7C7B;&#x672C;&#x8EAB;&#x5C31;&#x589E;&#x52A0;&#x4E86;&#x4E00;&#x5C42;&#x5D4C;&#x5957;&#x3002;
&#x9664;&#x975E;&#x5B83;&#x80FD;&#x65B9;&#x4FBF;&#x8868;&#x8FF0;&#x6216;&#x4FBF;&#x4E8E;&#x6E05;&#x6670;&#x4F7F;&#x7528;&#xFF0C;&#x5426;&#x5219;&#x8BF7;&#x8003;&#x8651;&#x76F4;&#x63A5;&#x5BFC;&#x51FA;&#x4E00;&#x4E2A;&#x8F85;&#x52A9;&#x65B9;&#x6CD5;&#x3002;</p>
<h3 id="&#x5982;&#x679C;&#x4EC5;&#x5BFC;&#x51FA;&#x5355;&#x4E2A;-class-&#x6216;-function&#xFF0C;&#x4F7F;&#x7528;-export-default">&#x5982;&#x679C;&#x4EC5;&#x5BFC;&#x51FA;&#x5355;&#x4E2A; <code>class</code> &#x6216; <code>function</code>&#xFF0C;&#x4F7F;&#x7528; <code>export default</code></h3>
<p>&#x5C31;&#x50CF;&#x201C;&#x5728;&#x9876;&#x5C42;&#x4E0A;&#x5BFC;&#x51FA;&#x201D;&#x5E2E;&#x52A9;&#x51CF;&#x5C11;&#x7528;&#x6237;&#x4F7F;&#x7528;&#x7684;&#x96BE;&#x5EA6;&#xFF0C;&#x4E00;&#x4E2A;&#x9ED8;&#x8BA4;&#x7684;&#x5BFC;&#x51FA;&#x4E5F;&#x80FD;&#x8D77;&#x5230;&#x8FD9;&#x4E2A;&#x6548;&#x679C;&#x3002;
&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x5C31;&#x662F;&#x4E3A;&#x4E86;&#x5BFC;&#x51FA;&#x7279;&#x5B9A;&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x90A3;&#x4E48;&#x4F60;&#x5E94;&#x8BE5;&#x8003;&#x8651;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x9ED8;&#x8BA4;&#x5BFC;&#x51FA;&#x3002;
&#x8FD9;&#x4F1A;&#x4EE4;&#x6A21;&#x5757;&#x7684;&#x5BFC;&#x5165;&#x548C;&#x4F7F;&#x7528;&#x53D8;&#x5F97;&#x4E9B;&#x8BB8;&#x7B80;&#x5355;&#x3002;
&#x6BD4;&#x5982;&#xFF1A;</p>
<h4 id="myclassts">MyClass.ts</h4>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-keyword">class</span> SomeType {
  <span class="hljs-keyword">constructor</span>() { ... }
}
</code></pre>
<h4 id="myfuncts">MyFunc.ts</h4>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getThing</span>(<span class="hljs-params"></span>) </span>{ <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;thing&apos;</span>; }
</code></pre>
<h4 id="consumerts">Consumer.ts</h4>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> t from <span class="hljs-string">&quot;./MyClass&quot;</span>;
<span class="hljs-keyword">import</span> f from <span class="hljs-string">&quot;./MyFunc&quot;</span>;
<span class="hljs-keyword">let</span> x = <span class="hljs-keyword">new</span> t();
<span class="hljs-built_in">console</span>.log(f());
</code></pre>
<p>&#x5BF9;&#x7528;&#x6237;&#x6765;&#x8BF4;&#x8FD9;&#x662F;&#x6700;&#x7406;&#x60F3;&#x7684;&#x3002;&#x4ED6;&#x4EEC;&#x53EF;&#x4EE5;&#x968F;&#x610F;&#x547D;&#x540D;&#x5BFC;&#x5165;&#x6A21;&#x5757;&#x7684;&#x7C7B;&#x578B;&#xFF08;&#x672C;&#x4F8B;&#x4E3A;<code>t</code>&#xFF09;&#x5E76;&#x4E14;&#x4E0D;&#x9700;&#x8981;&#x591A;&#x4F59;&#x7684;&#xFF08;.&#xFF09;&#x6765;&#x627E;&#x5230;&#x76F8;&#x5173;&#x5BF9;&#x8C61;&#x3002;</p>
<h3 id="&#x5982;&#x679C;&#x8981;&#x5BFC;&#x51FA;&#x591A;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x628A;&#x5B83;&#x4EEC;&#x653E;&#x5728;&#x9876;&#x5C42;&#x91CC;&#x5BFC;&#x51FA;">&#x5982;&#x679C;&#x8981;&#x5BFC;&#x51FA;&#x591A;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x628A;&#x5B83;&#x4EEC;&#x653E;&#x5728;&#x9876;&#x5C42;&#x91CC;&#x5BFC;&#x51FA;</h3>
<h4 id="mythingsts">MyThings.ts</h4>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> SomeType { <span class="hljs-comment">/* ... */</span> }
<span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">someFunc</span>(<span class="hljs-params"></span>) </span>{ <span class="hljs-comment">/* ... */</span> }
</code></pre>
<p>&#x76F8;&#x53CD;&#x5730;&#xFF0C;&#x5F53;&#x5BFC;&#x5165;&#x7684;&#x65F6;&#x5019;&#xFF1A;</p>
<h3 id="&#x660E;&#x786E;&#x5730;&#x5217;&#x51FA;&#x5BFC;&#x5165;&#x7684;&#x540D;&#x5B57;">&#x660E;&#x786E;&#x5730;&#x5217;&#x51FA;&#x5BFC;&#x5165;&#x7684;&#x540D;&#x5B57;</h3>
<h4 id="consumerts">Consumer.ts</h4>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { SomeType, SomeFunc } from <span class="hljs-string">&quot;./MyThings&quot;</span>;
<span class="hljs-keyword">let</span> x = <span class="hljs-keyword">new</span> SomeType();
<span class="hljs-keyword">let</span> y = someFunc();
</code></pre>
<h3 id="&#x4F7F;&#x7528;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x5BFC;&#x5165;&#x6A21;&#x5F0F;&#x5F53;&#x4F60;&#x8981;&#x5BFC;&#x51FA;&#x5927;&#x91CF;&#x5185;&#x5BB9;&#x7684;&#x65F6;&#x5019;">&#x4F7F;&#x7528;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x5BFC;&#x5165;&#x6A21;&#x5F0F;&#x5F53;&#x4F60;&#x8981;&#x5BFC;&#x51FA;&#x5927;&#x91CF;&#x5185;&#x5BB9;&#x7684;&#x65F6;&#x5019;</h3>
<h4 id="mylargemodulets">MyLargeModule.ts</h4>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> Dog { ... }
<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> Cat { ... }
<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> Tree { ... }
<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> Flower { ... }
</code></pre>
<h4 id="consumerts">Consumer.ts</h4>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> * as myLargeModule from <span class="hljs-string">&quot;./MyLargeModule.ts&quot;</span>;
<span class="hljs-keyword">let</span> x = <span class="hljs-keyword">new</span> myLargeModule.Dog();
</code></pre>
<h2 id="&#x4F7F;&#x7528;&#x91CD;&#x65B0;&#x5BFC;&#x51FA;&#x8FDB;&#x884C;&#x6269;&#x5C55;">&#x4F7F;&#x7528;&#x91CD;&#x65B0;&#x5BFC;&#x51FA;&#x8FDB;&#x884C;&#x6269;&#x5C55;</h2>
<p>&#x4F60;&#x53EF;&#x80FD;&#x7ECF;&#x5E38;&#x9700;&#x8981;&#x53BB;&#x6269;&#x5C55;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x7684;&#x529F;&#x80FD;&#x3002;
JS&#x91CC;&#x5E38;&#x7528;&#x7684;&#x4E00;&#x4E2A;&#x6A21;&#x5F0F;&#x662F;JQuery&#x90A3;&#x6837;&#x53BB;&#x6269;&#x5C55;&#x539F;&#x5BF9;&#x8C61;&#x3002;
&#x5982;&#x6211;&#x4EEC;&#x4E4B;&#x524D;&#x63D0;&#x5230;&#x7684;&#xFF0C;&#x6A21;&#x5757;&#x4E0D;&#x4F1A;&#x50CF;&#x5168;&#x5C40;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x5BF9;&#x8C61;&#x90A3;&#x6837;&#x53BB;<em>&#x5408;&#x5E76;</em>&#x3002;
&#x63A8;&#x8350;&#x7684;&#x65B9;&#x6848;&#x662F;<em>&#x4E0D;&#x8981;</em>&#x53BB;&#x6539;&#x53D8;&#x539F;&#x6765;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x800C;&#x662F;&#x5BFC;&#x51FA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x5B9E;&#x4F53;&#x6765;&#x63D0;&#x4F9B;&#x65B0;&#x7684;&#x529F;&#x80FD;&#x3002;</p>
<p>&#x5047;&#x8BBE;<code>Calculator.ts</code>&#x6A21;&#x5757;&#x91CC;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x8BA1;&#x7B97;&#x5668;&#x5B9E;&#x73B0;&#x3002;
&#x8FD9;&#x4E2A;&#x6A21;&#x5757;&#x540C;&#x6837;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x8F85;&#x52A9;&#x51FD;&#x6570;&#x6765;&#x6D4B;&#x8BD5;&#x8BA1;&#x7B97;&#x5668;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x901A;&#x8FC7;&#x4F20;&#x5165;&#x4E00;&#x7CFB;&#x5217;&#x8F93;&#x5165;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x5E76;&#x5728;&#x6700;&#x540E;&#x7ED9;&#x51FA;&#x7ED3;&#x679C;&#x3002;</p>
<h4 id="calculatorts">Calculator.ts</h4>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> Calculator {
    <span class="hljs-keyword">private</span> current = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">private</span> memory = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">private</span> operator: <span class="hljs-built_in">string</span>;

    <span class="hljs-keyword">protected</span> processDigit(digit: <span class="hljs-built_in">string</span>, currentValue: <span class="hljs-built_in">number</span>) {
        <span class="hljs-keyword">if</span> (digit &gt;= <span class="hljs-string">&quot;0&quot;</span> &amp;&amp; digit &lt;= <span class="hljs-string">&quot;9&quot;</span>) {
            <span class="hljs-keyword">return</span> currentValue * <span class="hljs-number">10</span> + (digit.charCodeAt(<span class="hljs-number">0</span>) - <span class="hljs-string">&quot;0&quot;</span>.charCodeAt(<span class="hljs-number">0</span>));
        }
    }

    <span class="hljs-keyword">protected</span> processOperator(operator: <span class="hljs-built_in">string</span>) {
        <span class="hljs-keyword">if</span> ([<span class="hljs-string">&quot;+&quot;</span>, <span class="hljs-string">&quot;-&quot;</span>, <span class="hljs-string">&quot;*&quot;</span>, <span class="hljs-string">&quot;/&quot;</span>].indexOf(operator) &gt;= <span class="hljs-number">0</span>) {
            <span class="hljs-keyword">return</span> operator;
        }
    }

    <span class="hljs-keyword">protected</span> evaluateOperator(operator: <span class="hljs-built_in">string</span>, left: <span class="hljs-built_in">number</span>, right: <span class="hljs-built_in">number</span>): <span class="hljs-built_in">number</span> {
        <span class="hljs-keyword">switch</span> (<span class="hljs-keyword">this</span>.operator) {
            <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;+&quot;</span>: <span class="hljs-keyword">return</span> left + right;
            <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;-&quot;</span>: <span class="hljs-keyword">return</span> left - right;
            <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;*&quot;</span>: <span class="hljs-keyword">return</span> left * right;
            <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;/&quot;</span>: <span class="hljs-keyword">return</span> left / right;
        }
    }

    <span class="hljs-keyword">private</span> evaluate() {
        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.operator) {
            <span class="hljs-keyword">this</span>.memory = <span class="hljs-keyword">this</span>.evaluateOperator(<span class="hljs-keyword">this</span>.operator, <span class="hljs-keyword">this</span>.memory, <span class="hljs-keyword">this</span>.current);
        }
        <span class="hljs-keyword">else</span> {
            <span class="hljs-keyword">this</span>.memory = <span class="hljs-keyword">this</span>.current;
        }
        <span class="hljs-keyword">this</span>.current = <span class="hljs-number">0</span>;
    }

    <span class="hljs-keyword">public</span> handleChar(char: <span class="hljs-built_in">string</span>) {
        <span class="hljs-keyword">if</span> (char === <span class="hljs-string">&quot;=&quot;</span>) {
            <span class="hljs-keyword">this</span>.evaluate();
            <span class="hljs-keyword">return</span>;
        }
        <span class="hljs-keyword">else</span> {
            <span class="hljs-keyword">let</span> value = <span class="hljs-keyword">this</span>.processDigit(char, <span class="hljs-keyword">this</span>.current);
            <span class="hljs-keyword">if</span> (value !== <span class="hljs-literal">undefined</span>) {
                <span class="hljs-keyword">this</span>.current = value;
                <span class="hljs-keyword">return</span>;
            }
            <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">let</span> value = <span class="hljs-keyword">this</span>.processOperator(char);
                <span class="hljs-keyword">if</span> (value !== <span class="hljs-literal">undefined</span>) {
                    <span class="hljs-keyword">this</span>.evaluate();
                    <span class="hljs-keyword">this</span>.operator = value;
                    <span class="hljs-keyword">return</span>;
                }
            }
        }
        <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">`Unsupported input: &apos;<span class="hljs-subst">${char}</span>&apos;`</span>);
    }

    <span class="hljs-keyword">public</span> getResult() {
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.memory;
    }
}

<span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params">c: Calculator, input: <span class="hljs-built_in">string</span></span>) </span>{
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; input.length; i++) {
        c.handleChar(input[i]);
    }

    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`result of &apos;<span class="hljs-subst">${input}</span>&apos; is &apos;<span class="hljs-subst">${c.getResult()}</span>&apos;`</span>);
}
</code></pre>
<p>&#x4E0B;&#x9762;&#x4F7F;&#x7528;&#x5BFC;&#x51FA;&#x7684;<code>test</code>&#x51FD;&#x6570;&#x6765;&#x6D4B;&#x8BD5;&#x8BA1;&#x7B97;&#x5668;&#x3002;</p>
<h4 id="testcalculatorts">TestCalculator.ts</h4>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { Calculator, test } from <span class="hljs-string">&quot;./Calculator&quot;</span>;


<span class="hljs-keyword">let</span> c = <span class="hljs-keyword">new</span> Calculator();
test(c, <span class="hljs-string">&quot;1+2*33/11=&quot;</span>); <span class="hljs-comment">// prints 9</span>
</code></pre>
<p>&#x73B0;&#x5728;&#x6269;&#x5C55;&#x5B83;&#xFF0C;&#x6DFB;&#x52A0;&#x652F;&#x6301;&#x8F93;&#x5165;&#x5176;&#x5B83;&#x8FDB;&#x5236;&#xFF08;&#x5341;&#x8FDB;&#x5236;&#x4EE5;&#x5916;&#xFF09;&#xFF0C;&#x8BA9;&#x6211;&#x4EEC;&#x6765;&#x521B;&#x5EFA;<code>ProgrammerCalculator.ts</code>&#x3002;</p>
<h4 id="programmercalculatorts">ProgrammerCalculator.ts</h4>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { Calculator } from <span class="hljs-string">&quot;./Calculator&quot;</span>;

<span class="hljs-keyword">class</span> ProgrammerCalculator extends Calculator {
    <span class="hljs-keyword">static</span> digits = [<span class="hljs-string">&quot;0&quot;</span>, <span class="hljs-string">&quot;1&quot;</span>, <span class="hljs-string">&quot;2&quot;</span>, <span class="hljs-string">&quot;3&quot;</span>, <span class="hljs-string">&quot;4&quot;</span>, <span class="hljs-string">&quot;5&quot;</span>, <span class="hljs-string">&quot;6&quot;</span>, <span class="hljs-string">&quot;7&quot;</span>, <span class="hljs-string">&quot;8&quot;</span>, <span class="hljs-string">&quot;9&quot;</span>, <span class="hljs-string">&quot;A&quot;</span>, <span class="hljs-string">&quot;B&quot;</span>, <span class="hljs-string">&quot;C&quot;</span>, <span class="hljs-string">&quot;D&quot;</span>, <span class="hljs-string">&quot;E&quot;</span>, <span class="hljs-string">&quot;F&quot;</span>];

    <span class="hljs-keyword">constructor</span>(public base: number) {
        <span class="hljs-keyword">super</span>();
        <span class="hljs-keyword">const</span> maxBase = ProgrammerCalculator.digits.length;
        <span class="hljs-keyword">if</span> (base &lt;= <span class="hljs-number">0</span> || base &gt; maxBase) {
            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">`base has to be within 0 to <span class="hljs-subst">${maxBase}</span> inclusive.`</span>);
        }
    }

    <span class="hljs-keyword">protected</span> processDigit(digit: <span class="hljs-built_in">string</span>, currentValue: <span class="hljs-built_in">number</span>) {
        <span class="hljs-keyword">if</span> (ProgrammerCalculator.digits.indexOf(digit) &gt;= <span class="hljs-number">0</span>) {
            <span class="hljs-keyword">return</span> currentValue * <span class="hljs-keyword">this</span>.base + ProgrammerCalculator.digits.indexOf(digit);
        }
    }
}

<span class="hljs-comment">// Export the new extended calculator as Calculator</span>
<span class="hljs-keyword">export</span> { ProgrammerCalculator as Calculator };

<span class="hljs-comment">// Also, export the helper function</span>
<span class="hljs-keyword">export</span> { test } from <span class="hljs-string">&quot;./Calculator&quot;</span>;
</code></pre>
<p>&#x65B0;&#x7684;<code>ProgrammerCalculator</code>&#x6A21;&#x5757;&#x5BFC;&#x51FA;&#x7684;API&#x4E0E;&#x539F;&#x5148;&#x7684;<code>Calculator</code>&#x6A21;&#x5757;&#x5F88;&#x76F8;&#x4F3C;&#xFF0C;&#x4F46;&#x5374;&#x6CA1;&#x6709;&#x6539;&#x53D8;&#x539F;&#x6A21;&#x5757;&#x91CC;&#x7684;&#x5BF9;&#x8C61;&#x3002;
&#x4E0B;&#x9762;&#x662F;&#x6D4B;&#x8BD5;ProgrammerCalculator&#x7C7B;&#x7684;&#x4EE3;&#x7801;&#xFF1A;</p>
<h4 id="testprogrammercalculatorts">TestProgrammerCalculator.ts</h4>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { Calculator, test } from <span class="hljs-string">&quot;./ProgrammerCalculator&quot;</span>;

<span class="hljs-keyword">let</span> c = <span class="hljs-keyword">new</span> Calculator(<span class="hljs-number">2</span>);
test(c, <span class="hljs-string">&quot;001+010=&quot;</span>); <span class="hljs-comment">// prints 3</span>
</code></pre>
<h2 id="&#x6A21;&#x5757;&#x91CC;&#x4E0D;&#x8981;&#x4F7F;&#x7528;&#x547D;&#x540D;&#x7A7A;&#x95F4;">&#x6A21;&#x5757;&#x91CC;&#x4E0D;&#x8981;&#x4F7F;&#x7528;&#x547D;&#x540D;&#x7A7A;&#x95F4;</h2>
<p>&#x5F53;&#x521D;&#x6B21;&#x8FDB;&#x5165;&#x57FA;&#x4E8E;&#x6A21;&#x5757;&#x7684;&#x5F00;&#x53D1;&#x6A21;&#x5F0F;&#x65F6;&#xFF0C;&#x53EF;&#x80FD;&#x603B;&#x4F1A;&#x63A7;&#x5236;&#x4E0D;&#x4F4F;&#x8981;&#x5C06;&#x5BFC;&#x51FA;&#x5305;&#x88F9;&#x5728;&#x4E00;&#x4E2A;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x91CC;&#x3002;
&#x6A21;&#x5757;&#x5177;&#x6709;&#x5176;&#x81EA;&#x5DF1;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x5E76;&#x4E14;&#x53EA;&#x6709;&#x5BFC;&#x51FA;&#x7684;&#x58F0;&#x660E;&#x624D;&#x4F1A;&#x5728;&#x6A21;&#x5757;&#x5916;&#x90E8;&#x53EF;&#x89C1;&#x3002;
&#x8BB0;&#x4F4F;&#x8FD9;&#x70B9;&#xFF0C;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x5728;&#x4F7F;&#x7528;&#x6A21;&#x5757;&#x65F6;&#x51E0;&#x4E4E;&#x6CA1;&#x4EC0;&#x4E48;&#x4EF7;&#x503C;&#x3002;</p>
<p>&#x5728;&#x7EC4;&#x7EC7;&#x65B9;&#x9762;&#xFF0C;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x5BF9;&#x4E8E;&#x5728;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x5185;&#x5BF9;&#x903B;&#x8F91;&#x4E0A;&#x76F8;&#x5173;&#x7684;&#x5BF9;&#x8C61;&#x548C;&#x7C7B;&#x578B;&#x8FDB;&#x884C;&#x5206;&#x7EC4;&#x662F;&#x5F88;&#x4FBF;&#x5229;&#x7684;&#x3002;
&#x4F8B;&#x5982;&#xFF0C;&#x5728;C#&#x91CC;&#xFF0C;&#x4F60;&#x4F1A;&#x4ECE;<code>System.Collections</code>&#x91CC;&#x627E;&#x5230;&#x6240;&#x6709;&#x96C6;&#x5408;&#x7684;&#x7C7B;&#x578B;&#x3002;
&#x901A;&#x8FC7;&#x5C06;&#x7C7B;&#x578B;&#x6709;&#x5C42;&#x6B21;&#x5730;&#x7EC4;&#x7EC7;&#x5728;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x91CC;&#xFF0C;&#x53EF;&#x4EE5;&#x65B9;&#x4FBF;&#x7528;&#x6237;&#x627E;&#x5230;&#x4E0E;&#x4F7F;&#x7528;&#x90A3;&#x4E9B;&#x7C7B;&#x578B;&#x3002;
&#x7136;&#x800C;&#xFF0C;&#x6A21;&#x5757;&#x672C;&#x8EAB;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x4E8E;&#x6587;&#x4EF6;&#x7CFB;&#x7EDF;&#x4E4B;&#x4E2D;&#xFF0C;&#x8FD9;&#x662F;&#x5FC5;&#x987B;&#x7684;&#x3002;
&#x6211;&#x4EEC;&#x5FC5;&#x987B;&#x901A;&#x8FC7;&#x8DEF;&#x5F84;&#x548C;&#x6587;&#x4EF6;&#x540D;&#x627E;&#x5230;&#x5B83;&#x4EEC;&#xFF0C;&#x8FD9;&#x5DF2;&#x7ECF;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x79CD;&#x903B;&#x8F91;&#x4E0A;&#x7684;&#x7EC4;&#x7EC7;&#x5F62;&#x5F0F;&#x3002;
&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x521B;&#x5EFA;<code>/collections/generic/</code>&#x6587;&#x4EF6;&#x5939;&#xFF0C;&#x628A;&#x76F8;&#x5E94;&#x6A21;&#x5757;&#x653E;&#x5728;&#x8FD9;&#x91CC;&#x9762;&#x3002;</p>
<p>&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x5BF9;&#x89E3;&#x51B3;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x91CC;&#x547D;&#x540D;&#x51B2;&#x7A81;&#x6765;&#x8BF4;&#x662F;&#x5F88;&#x91CD;&#x8981;&#x7684;&#x3002;
&#x6BD4;&#x5982;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x6709;&#x4E00;&#x4E2A;<code>My.Application.Customer.AddForm</code>&#x548C;<code>My.Application.Order.AddForm</code> -- &#x4E24;&#x4E2A;&#x7C7B;&#x578B;&#x7684;&#x540D;&#x5B57;&#x76F8;&#x540C;&#xFF0C;&#x4F46;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x4E0D;&#x540C;&#x3002;
&#x7136;&#x800C;&#xFF0C;&#x8FD9;&#x5BF9;&#x4E8E;&#x6A21;&#x5757;&#x6765;&#x8BF4;&#x5374;&#x4E0D;&#x662F;&#x4E00;&#x4E2A;&#x95EE;&#x9898;&#x3002;
&#x5728;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x91CC;&#xFF0C;&#x6CA1;&#x6709;&#x7406;&#x7531;&#x4E24;&#x4E2A;&#x5BF9;&#x8C61;&#x62E5;&#x6709;&#x540C;&#x4E00;&#x4E2A;&#x540D;&#x5B57;&#x3002;
&#x4ECE;&#x6A21;&#x5757;&#x7684;&#x4F7F;&#x7528;&#x89D2;&#x5EA6;&#x6765;&#x8BF4;&#xFF0C;&#x4F7F;&#x7528;&#x8005;&#x4F1A;&#x6311;&#x51FA;&#x4ED6;&#x4EEC;&#x7528;&#x6765;&#x5F15;&#x7528;&#x6A21;&#x5757;&#x7684;&#x540D;&#x5B57;&#xFF0C;&#x6240;&#x4EE5;&#x4E5F;&#x6CA1;&#x6709;&#x7406;&#x7531;&#x53D1;&#x751F;&#x91CD;&#x540D;&#x7684;&#x60C5;&#x51B5;&#x3002;</p>
<blockquote>
<p>&#x66F4;&#x591A;&#x5173;&#x4E8E;&#x6A21;&#x5757;&#x548C;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x7684;&#x8D44;&#x6599;&#x67E5;&#x770B;<a href="Namespaces%20and%20Modules.md">&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x548C;&#x6A21;&#x5757;</a></p>
</blockquote>
<h2 id="&#x5371;&#x9669;&#x4FE1;&#x53F7;">&#x5371;&#x9669;&#x4FE1;&#x53F7;</h2>
<p>&#x4EE5;&#x4E0B;&#x5747;&#x4E3A;&#x6A21;&#x5757;&#x7ED3;&#x6784;&#x4E0A;&#x7684;&#x5371;&#x9669;&#x4FE1;&#x53F7;&#x3002;&#x91CD;&#x65B0;&#x68C0;&#x67E5;&#x4EE5;&#x786E;&#x4FDD;&#x4F60;&#x6CA1;&#x6709;&#x5728;&#x5BF9;&#x6A21;&#x5757;&#x4F7F;&#x7528;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#xFF1A;</p>
<ul>
<li>&#x6587;&#x4EF6;&#x7684;&#x9876;&#x5C42;&#x58F0;&#x660E;&#x662F;<code>export namespace Foo { ... }</code> &#xFF08;&#x5220;&#x9664;<code>Foo</code>&#x5E76;&#x628A;&#x6240;&#x6709;&#x5185;&#x5BB9;&#x5411;&#x4E0A;&#x5C42;&#x79FB;&#x52A8;&#x4E00;&#x5C42;&#xFF09;</li>
<li>&#x6587;&#x4EF6;&#x53EA;&#x6709;&#x4E00;&#x4E2A;<code>export class</code>&#x6216;<code>export function</code> &#xFF08;&#x8003;&#x8651;&#x4F7F;&#x7528;<code>export default</code>&#xFF09;</li>
<li>&#x591A;&#x4E2A;&#x6587;&#x4EF6;&#x7684;&#x9876;&#x5C42;&#x5177;&#x6709;&#x540C;&#x6837;&#x7684;<code>export namespace Foo {</code> &#xFF08;&#x4E0D;&#x8981;&#x4EE5;&#x4E3A;&#x8FD9;&#x4E9B;&#x4F1A;&#x5408;&#x5E76;&#x5230;&#x4E00;&#x4E2A;<code>Foo</code>&#x4E2D;&#xFF01;&#xFF09;</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Iterators and Generators.html" class="navigation navigation-prev " aria-label="Previous page: Iterators 和 Generators">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Namespaces.html" class="navigation navigation-next " aria-label="Next page: 命名空间">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"模块","level":"1.3.14","depth":2,"next":{"title":"命名空间","level":"1.3.15","depth":2,"path":"doc/handbook/Namespaces.md","ref":"./doc/handbook/Namespaces.md","articles":[]},"previous":{"title":"Iterators 和 Generators","level":"1.3.13","depth":2,"path":"doc/handbook/Iterators and Generators.md","ref":"./doc/handbook/Iterators and Generators.md","articles":[]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Patrick Zhong","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"preface.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"TypeScript Handbook","language":"zh-hans","gitbook":">3.0.0","description":"Translation of official TypeScript Handbook"},"file":{"path":"doc/handbook/Modules.md","mtime":"2018-10-13T09:48:54.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-13T09:57:42.904Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

